<template>
    <van-form>
        <van-field placeholder="请输入用户名" v-model="username" />
        <van-field placeholder="请输入密码" v-model="password" />
        <div style="margin: 16px;">
            <van-button @click="login">
                登录
            </van-button>
            <span>
                <van-button @click="add" style="margin-left:180px;">
                    注册
                </van-button>
            </span>
        </div>
    </van-form>
</template>

<script>
import axios from "axios";
export default {
    data() {
        return {
            username: "",
            password: "",
        };
    },
    methods: {
        async login() {
            await axios
                .post("/denglu", {
                    username: this.username,
                    password: this.password,
                })
                .then((res) => {
                    if (res.data.code == 401) {
                        alert("输入账号密码错误");
                    } else {
                        //跳转到列表页
                        this.$router.push("/main");
                        console.log(res);
                    }
                });
        },
        async add() {
            //跳转注册页面
            this.$router.push("/add");
        },
    },
};
</script>

<style></style>
